import java.awt.*;
import java.util.Scanner;

public class towork6 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m= sc.nextInt();
        int [][]arr=new int[n][m];
        for (int i=0;i<n;i++){
            for (int j=0;j<m;j++){
                arr[i][j]= sc.nextInt();
            }
        }
        int  temp=Integer.MIN_VALUE;
        for (int x1 = 0; x1 <n ; x1++) {
            for (int  y1= 0;y1 <m ; y1++) {
                for (int len=1;x1+len<n&&y1+len<m;len++){
                    int x2=x1+len;
                    int y2=len+y1;
                    int sum=0;
                    for (int y=y1;y<=y2;y++){
                        sum+=arr[x1][y];
                    }for (int y=y1;y<=y2;y++){
                        sum+=arr[x2][y];
                    }
                    for (int x=x1+1;x<x2;x++){
                        sum+=arr[x][y1];
                    }
                    for (int x=x1+1;x<x2;x++){
                        sum+=arr[x][y2];
                    }
                    temp=Math.max(sum,temp);

                }
            }
        }
        System.out.println(temp);
    }
}
